/*
  This file is part of bnc.

  bnc is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  bnc is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with bnc.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "manager.h"

const char cHelp[]="\
bnc ('barely noticable compression') v1.05\n\
\n\
usage:\
\tbnc c output input\tto archive files\n \
\tbnc x input\t\tto extract files (or subset of files)\n\
\tbnc l input\t\tto list out files\n\
\n\
\texamples:\n\
\tbnc c archive file0 -n file1 -c file2\n\
\tbnc x archive\n\
\tbnc x archive file0 file2\n\
\tbnc l archive\n\
\n\
\tinput files are compressed by default\n\
\tuse -n to avoid compression or encryption of following files\n\
\tuse -c to compress again\n\
\tuse -e to encrypt following files\n\
";

int main (int argc, char** argv)
{
  manager lManager;

  if (argc<2)
  {
    printf("%s", cHelp);
    return 0;
  }

  managerConstructor(&lManager);

  /*
    Create archive.
  */
  if (argv[1][0]=='c' && argv[1][1]==0 && argc>3)
  {
    if (managerCreateBnc(&lManager, argv[2]))
      managerInsertFiles(&lManager, argc-3, &argv[3]);
  } else if (argv[1][0]=='c' && argv[1][1]==0 && argc>2) {
    if (managerCreateBnc(&lManager, argv[2]))
      managerInsertFiles(&lManager, 0, NULL);
  }

  /*
    Extract files from archive.
  */
  else if (argv[1][0]=='x' && argv[1][1]==0 && argc>2) {
    if (managerOpenBnc(&lManager, argv[2]))
      managerExtractFiles(&lManager, argc-3, &argv[3]);
  }

  /*
    List out the files in archive.
  */
  else if (argv[1][0]=='l' && argv[1][1]==0 && argc>2) {
    if (managerOpenBnc(&lManager, argv[2]))
      managerListFiles(&lManager);
  }

  /*
    Otherwise print out the help message.
  */
  else {
    printf("%s", cHelp);
  }

  managerDestructor(&lManager);

  return 0;
}
